/*
 // * created feb 18, 2006
 */
package dk.aiszone.lang.comparators;

import java.util.Comparator;

import dk.aiszone.lang.comparatorfactory.ComparatorObjectProvider;

/**
 * Implementation of the TestCF1 <code>Comparator</code>.
 * 
 */
public class TestCF1 implements Comparator {

    private ComparatorObjectProvider objectProvider;

    public TestCF1(ComparatorObjectProvider objectProvider) {
        this.objectProvider = objectProvider;
    }

    public int compare(Object arg1, Object arg2) {
        int val;

        dk.aiszone.lang.comparatorfactory.TestObject testObject1 = (dk.aiszone.lang.comparatorfactory.TestObject)objectProvider.getObject(arg1, "testObject");
        dk.aiszone.lang.comparatorfactory.TestObject testObject2 = (dk.aiszone.lang.comparatorfactory.TestObject)objectProvider.getObject(arg2, "testObject");

        Comparable testObject1_valueOne = testObject1.getvalueOne();
        Comparable testObject2_valueOne = testObject2.getvalueOne();
        if (testObject1_valueOne == null && testObject2_valueOne == null) {
            val = 0;
        } else if (testObject1_valueOne != null && testObject2_valueOne == null) {
            val = -1;
        } else if (testObject1_valueOne == null && testObject2_valueOne != null) {
            val = 1;
        } else {
            val = testObject1_valueOne.compareTo(testObject2_valueOne);
        }
        if (val != 0) {
            return val;
        }

        dk.aiszone.lang.comparatorfactory.OtherTestObject otherTestObject1 = (dk.aiszone.lang.comparatorfactory.OtherTestObject)objectProvider.getObject(arg1, "otherTestObject");
        dk.aiszone.lang.comparatorfactory.OtherTestObject otherTestObject2 = (dk.aiszone.lang.comparatorfactory.OtherTestObject)objectProvider.getObject(arg2, "otherTestObject");

        Comparable otherTestObject1_valueOne = otherTestObject1.getvalueOne();
        Comparable otherTestObject2_valueOne = otherTestObject2.getvalueOne();
        if (otherTestObject1_valueOne == null && otherTestObject2_valueOne == null) {
            val = 0;
        } else if (otherTestObject1_valueOne != null && otherTestObject2_valueOne == null) {
            val = -1;
        } else if (otherTestObject1_valueOne == null && otherTestObject2_valueOne != null) {
            val = 1;
        } else {
            val = otherTestObject1_valueOne.compareTo(otherTestObject2_valueOne);
        }
        if (val != 0) {
            return val;
        }

        Comparable testObject1_valueTwo = testObject1.getvalueTwo();
        Comparable testObject2_valueTwo = testObject2.getvalueTwo();
        if (testObject1_valueTwo == null && testObject2_valueTwo == null) {
            val = 0;
        } else if (testObject1_valueTwo != null && testObject2_valueTwo == null) {
            val = -1;
        } else if (testObject1_valueTwo == null && testObject2_valueTwo != null) {
            val = 1;
        } else {
            val = testObject1_valueTwo.compareTo(testObject2_valueTwo);
        }
        if (val != 0) {
            return val;
        }

        return 0;
    }

    /**
     * Returns a <code>String</code> containing the implementation of the <code>compareTo(Object, Object)</code> method.
     * 
     * @return <code>String</code> representation of the comparator implementation.
     */
    public String toString() {
        return "public int compare(Object arg1, Object arg2) {\n    int val;\n\n    dk.aiszone.lang.comparatorfactory.TestObject testObject1 = (dk.aiszone.lang.comparatorfactory.TestObject)objectProvider.getObject(arg1, \"testObject\");\n    dk.aiszone.lang.comparatorfactory.TestObject testObject2 = (dk.aiszone.lang.comparatorfactory.TestObject)objectProvider.getObject(arg2, \"testObject\");\n\n    Comparable testObject1_valueOne = testObject1.getvalueOne();\n    Comparable testObject2_valueOne = testObject2.getvalueOne();\n    if (testObject1_valueOne == null && testObject2_valueOne == null) {\n        val = 0;\n    } else if (testObject1_valueOne != null && testObject2_valueOne == null) {\n        val = -1;\n    } else if (testObject1_valueOne == null && testObject2_valueOne != null) {\n        val = 1;\n    } else {\n        val = testObject1_valueOne.compareTo(testObject2_valueOne);\n    }\n    if (val != 0) {\n        return val;\n    }\n\n    dk.aiszone.lang.comparatorfactory.OtherTestObject otherTestObject1 = (dk.aiszone.lang.comparatorfactory.OtherTestObject)objectProvider.getObject(arg1, \"otherTestObject\");\n    dk.aiszone.lang.comparatorfactory.OtherTestObject otherTestObject2 = (dk.aiszone.lang.comparatorfactory.OtherTestObject)objectProvider.getObject(arg2, \"otherTestObject\");\n\n    Comparable otherTestObject1_valueOne = otherTestObject1.getvalueOne();\n    Comparable otherTestObject2_valueOne = otherTestObject2.getvalueOne();\n    if (otherTestObject1_valueOne == null && otherTestObject2_valueOne == null) {\n        val = 0;\n    } else if (otherTestObject1_valueOne != null && otherTestObject2_valueOne == null) {\n        val = -1;\n    } else if (otherTestObject1_valueOne == null && otherTestObject2_valueOne != null) {\n        val = 1;\n    } else {\n        val = otherTestObject1_valueOne.compareTo(otherTestObject2_valueOne);\n    }\n    if (val != 0) {\n        return val;\n    }\n\n    Comparable testObject1_valueTwo = testObject1.getvalueTwo();\n    Comparable testObject2_valueTwo = testObject2.getvalueTwo();\n    if (testObject1_valueTwo == null && testObject2_valueTwo == null) {\n        val = 0;\n    } else if (testObject1_valueTwo != null && testObject2_valueTwo == null) {\n        val = -1;\n    } else if (testObject1_valueTwo == null && testObject2_valueTwo != null) {\n        val = 1;\n    } else {\n        val = testObject1_valueTwo.compareTo(testObject2_valueTwo);\n    }\n    if (val != 0) {\n        return val;\n    }\n\n    return 0;\n}\n";
    }

    /**
     * Returns a <code>String</code> containing the XML definition which lay basis for the <code>Comparator</code>.
     * 
     * @return <code>String</code> representation of the comparator definition.
     */
    public String toXMLString() {
        return "<comparator name=\"TestCF1\">\n  <comparator-object id=\"testObject\" class=\"dk.aiszone.lang.comparatorfactory.TestObject\" />\n  <comparator-object id=\"otherTestObject\" class=\"dk.aiszone.lang.comparatorfactory.OtherTestObject\" />\n  <comparator-definition id=\"one\">\n    <comparator-item object=\"testObject\" attribute=\"valueOne\" descending=\"true\" />\n    <comparator-item object=\"otherTestObject\" attribute=\"valueOne\" />\n    <comparator-item object=\"testObject\" attribute=\"valueTwo\" descending=\"true\" />\n  </comparator-definition>\n</comparator>";
    }

}